#include <array>
#include <cmath>
#include <iostream>
using namespace std;
using arr2r = std::array<double, 2>;

struct VecTrans {
  double u[2][2];
  void init(double angle) {
    u[0][0] = cos(angle);
    u[0][1] = -sin(angle);
    u[1][0] = sin(angle);
    u[1][1] = cos(angle);
  }
  /// 会覆盖x中的值 x指笛卡尔坐标  c 指旋转坐标
  void c2x(const arr2r &c, arr2r &x) const {
    x[0] = u[0][0] * c[0] + u[0][1] * c[1];
    x[1] = u[1][0] * c[0] + u[1][1] * c[1];
  }
  /// 会覆盖c中的值 x指笛卡尔坐标  c 指旋转坐标
  void x2c(const arr2r &x, arr2r &c) const {
    c[0] = u[0][0] * x[0] + u[1][0] * x[1];
    c[1] = u[0][1] * x[0] + u[1][1] * x[1];
  }
};

constexpr double TOLERANCE{1.0e-12}, PI{3.1415926535897932};

int main() {
  arr2r x{1, 1};
  const double angle = 45 / 180.0 * PI;
  VecTrans trans;
  trans.init(angle);
  arr2r c;
  trans.x2c(x, c);
  cout << c[0] << "  " << c[1] << endl;
  trans.c2x(c, x);
  cout << x[0] << "  " << x[1] << endl;

  return 0;
}